import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:management/utils/custom_router.dart';
import 'package:management/views/mine/userInfo/change_psw.dart';
import 'package:management/views/mine/userInfo/search_gate_record_condition.dart';

///账号信息
class UserInfo extends StatefulWidget {
  @override
  _UserInfoState createState() => _UserInfoState();
}

class _UserInfoState extends State<UserInfo> {
  late String userName;

  @override
  void initState() {
    SystemChrome.setEnabledSystemUIOverlays([]);
    super.initState();
    userName = SpUtil.getString("userName", defValue: "无")!;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          iconSize: 35,
          icon: Icon(Icons.arrow_back),
          onPressed: () => Navigator.of(context).pop(),
        ),
        title: Text(
          "管理员信息",
          style: TextStyle(
            fontSize: 25,
          ),
        ),
        centerTitle: true,
      ),
      body: Container(
        height: userName == "admin" ? 280 : 220,
        child: Column(
          children: [
            ListTile(
              leading: Icon(Icons.account_circle_sharp),
              title: Row(
                children: [
                  Text(
                    "账号：",
                    style: TextStyle(fontSize: 30),
                  ),
                  Text(
                    userName,
                    style: TextStyle(fontSize: 30),
                  ),
                ],
              ),
            ),
            Divider(),
            userName == "admin"
                ? ListTile(
                    leading: Icon(Icons.edit),
                    title: Text(
                      "修改密码",
                      style: TextStyle(fontSize: 30),
                    ),
                    trailing: Icon(
                      Icons.chevron_right,
                      size: 40,
                    ),
                    onTap: () =>
                        //Navigator.of(context).pushNamed('/ChangePassword'),
                        Navigator.push(context, SlideRoute(ChangePassword())),
                  )
                : SizedBox(),
            userName == "admin" ? Divider() : SizedBox(),
            ListTile(
              leading: Icon(Icons.receipt),
              title: Text(
                "开闸记录",
                style: TextStyle(fontSize: 30),
              ),
              trailing: Icon(
                Icons.chevron_right,
                size: 40,
              ),
              onTap: () {
                // Navigator.of(context).pushNamed('/SearchGateRecordCondition');
                Navigator.push(
                    context, SlideRoute(SearchGateRecordCondition()));
              },
            ),
            Divider(),
            Expanded(
              child: Padding(
                padding: EdgeInsets.only(top: 20),
                child: MaterialButton(
                  minWidth: 350,
                  height: 50,
                  color: Colors.blue,
                  onPressed: () {
                    Navigator.of(context)
                        .popUntil(ModalRoute.withName('/LoginPage'));
                    Navigator.of(context).pushNamed('/LoginPage');
                  },
                  child: Text(
                    "退出登录",
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 20,
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
